import 'package:flutter/material.dart';
import 'package:flutter_app/components/layout.dart';
import '../../components/BottomSheetModal.dart';

class SecurityPage extends StatefulWidget {
  @override
  _SecurityPageState createState() => _SecurityPageState();
}

Widget ListItem(String text, {Widget right, Function onPressed}) {
  return Padding(
    padding: const EdgeInsets.symmetric(vertical: 15.0),
    child: GestureDetector(
      onTap: onPressed ?? () {},
      child: RowBetween(children: [
        Expanded(
          flex: 1,
          child: Text(
            text,
            style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
          ),
        ),
        Offstage(offstage: right == null, child: right)
      ]),
    ),
  );
}

Widget Arrow() {
  return Icon(
    Icons.arrow_forward_ios_outlined,
    size: 13,
    color: Colors.grey,
  );
}

class _SecurityPageState extends State<SecurityPage> with ChangeNotifier {
  bool fingerprint;
  bool gesture;

  void initState() {
    super.initState();
    fingerprint = false;
    gesture = false;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: DarkHeadBar('账户安全'),
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20.0),
          child: Column(
            children: [
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      ListItem('手机',
                          right: Text(
                            '180****6091',
                            style: TextStyle(color: Colors.grey, fontSize: 15),
                          )),
                      ListItem('邮箱',
                          right: Row(
                            children: [
                              Text(
                                '设置',
                                style: TextStyle(
                                    color: Colors.blueAccent,
                                    fontSize: 15,
                                    fontWeight: FontWeight.w500),
                              ),
                              SizedBox(
                                width: 6,
                              ),
                              Arrow()
                            ],
                          ), onPressed: () {
                            BottomSheetModal.setMail(context);
                      }),
                      ListItem('谷歌验证码',
                          right: Row(
                            children: [
                              Text(
                                '设置',
                                style: TextStyle(
                                    color: Colors.blueAccent,
                                    fontSize: 15,
                                    fontWeight: FontWeight.w500),
                              ),
                              SizedBox(
                                width: 6,
                              ),
                              Arrow(),
                            ],
                          ), onPressed: () {
                        Navigator.pushNamed(context, '/google/step1');
                      }),
                      ListItem('登录密码',
                          right: Image.asset(
                            'assets/images/ic_had_set.png',
                            width: 25,
                          )),
                      ListItem('资金密码',
                          right: Row(
                            children: [
                              Text(
                                '设置',
                                style: TextStyle(
                                    color: Colors.blueAccent,
                                    fontSize: 15,
                                    fontWeight: FontWeight.w500),
                              ),
                              SizedBox(
                                width: 6,
                              ),
                              Arrow()
                            ],
                          ), onPressed: () {
                        // method.setFoundPsw();
                        BottomSheetModal.setFundPsw(context);
                      }),
                      ListItem('提币地址', right: Arrow(), onPressed: () {
                        Navigator.pushNamed(context, '/safe/warning');
                      }),
                      SizedBox(
                        height: 30,
                      ),
                      ListItem('指纹登录',
                          right: Container(
                            height: 20,
                            child: Switch(
                                value: fingerprint,
                                onChanged: (value) {
                                  fingerprint = value;
                                  setState(() {
                                    fingerprint = value;
                                  });
                                }),
                          )),
                      ListItem('手势密码',
                          right: Container(
                            height: 20,
                            alignment: Alignment.centerRight,
                            child: Switch(
                                value: gesture,
                                onChanged: (value) {
                                  gesture = value;
                                  setState(() {
                                    gesture = value;
                                  });
                                }),
                          )),
                    ],
                  ),
                ),
              ),
              Container(
                  margin: EdgeInsets.only(bottom: 10),
                  width: MediaQuery.of(context).size.width,
                  child: FlatButton(
                      color: Colors.blueAccent.withOpacity(0.05),
                      textColor: Colors.blueAccent,
                      onPressed: () {},
                      child: Text('登出')))
            ],
          ),
        ));
  }
}
